<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台管理系统</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">小苏的后台管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    贤心
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="">退了</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="menu">

                <li class="layui-nav-item layui-nav-itemed" th:each="permission : ${permissionList}">
                    <a class="" th:lay-id="${permission.url}" th:lay-flag="${permission.name=='系统管理'?'menu':''}"  href="javascript:;">[[${permission.name}]]</a>
                    <dl class="layui-nav-child" th:each="chp : ${permission.sonePermissionList}">
                        <dd><a th:lay-id="${chp.url}" href="javascript:;">[[${chp.name}]]</a></dd>
                        <!--<dd><a lay-id="personnelManagement" href="javascript:;">用户管理</a></dd>
                        <dd><a lay-id="roleManagement" href="javascript:;">角色管理</a></dd>
                        <dd><a lay-id="menuManagement" href="javascript:;">菜单管理</a></dd>-->
                    </dl>
                </li>
                <!--<li class="layui-nav-item layui-nav-itemed">
                    <a class="" lay-id="engineering"  href="javascript:;">工程管理首页</a>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" lay-id="epidemic"  href="javascript:;">疫情地图</a>
                </li>-->

            </ul>

        </div>
    </div>

    <div class="layui-body" >
        <!-- 内容主体区域 -->
        <div class="layui-tab" lay-allowClose="true" lay-filter="demo">
            <ul class="layui-tab-title">
                <!--<li class="layui-this">菜单管理</li>
                <li>人员管理</li>
                <li>角色管理</li>
                <li>权限管理</li>-->
            </ul>
            <div class="layui-tab-content"  >
                <!--<div class="layui-tab-item layui-show">1</div>
                <div class="layui-tab-item">2</div>
                <div class="layui-tab-item">3</div>
                <div class="layui-tab-item">4</div>-->
            </div>
        </div>

    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->

        © layui.com - 底部固定区域
    </div>
</div>
<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/lay/modules/jquery.js}"></script>
<script>
    //JavaScript代码区域
    layui.use(['element','jquery'], function(){
        var element = layui.element;
        var $ = layui.jquery;
        //获取当前用户的所有菜单权限
        var uid = `[[${userid}]]`+""
        $.post("/getUserPermission",{uid:uid},function (data) {
            console.log(data)
        })

        // 添加tab栏
        function addTab(title,content,id){
            element.tabAdd('demo', {
                title: ''+title
                ,content: ''+content //支持传入html
                ,id: ''+id
            });
        }

        // 单击菜单时添加tab栏
        element.on('nav(menu)',function (data) {
            if($(this).attr('lay-flag')=='menu'){
                return;
            }

            let id = $(this).attr('lay-id')
            let title = $(this).text()
            let content = `<iframe style="width: 100%; height: 830px;"  src="/toPage/management/${id}" scrolling="no"   frameborder="0"></iframe>`

            let tabArr = $('.layui-tab-title').find('li');
            let flag = true;
            for (let i = 0; i < tabArr.length; i++) {
                if($(tabArr[i]).attr('lay-id')==id){
                    flag = false;
                }
            }

            if(flag){
                addTab(title,content,id)
            }

            element.tabChange('demo', id);
        })


    });
</script>
</body>
</html>